{% extends 'admin/common/base.html' %}
{% block body %}
<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="type-form">
					<div class="select-list">
						<ul>
							<li>
								名称：<input type="text" name="name" value="{{request.values.get('name','')}}"/>
							</li>
							<li>
								<button class="btn btn-primary btn-rounded btn-sm" type="submit"><i class="fa fa-search"></i>&nbsp;搜索</button>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

            <div class="btn-group-sm" id="toolbar" role="group">
                {% set url = url_for('admin.${m.tpl_path}.add') %}
                <a class="btn btn-success" onclick="$.modal.open('添加${m.name}', '{{url}}');">
                    <i class="fa fa-plus"></i> 新增
                </a>
            </div>
			
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table" class="table">
                    <thead>
                        % for c in m.columns:
                        % if c.is_list == 1:
                        <th>${c.col_comment}</th>
                        % endif
                        % endfor
                        <th>操作</th>
                    </thead>
                    <tbody>
                        {% for d in list_page.items %}
                        <tr>
                            % for c in m.columns:
                            % if c.is_list == 1:
                            <td>{{d.${c.col_name}}}</td>
                            % endif
                            % endfor
                            <td>
                                {%set url = url_for('admin.${m.tpl_path}.edit', id=d.id) %}
                                <a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.modal.open('修改${m.name}', '{{url}}')"><i class="fa fa-edit"></i>编辑</a>
                                <a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="remove('{{d.id}}')"><i class="fa fa-remove"></i>删除</a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% import "admin/macros/_patination.html" as macro %}
    			{{ macro.pagination_widget(list_page, request.endpoint , **(request.values.to_dict() | request_page_params )) }}
			</div>
		</div>
    </div>
</body>
{% endblock %}
{% block js %}
{{ super() }}
<script>

    function remove(id) {
        $.modal.confirm("确定删除吗？", function() {
            $.operate.post("{{url_for('admin.${m.tpl_path}.remove')}}", { "ids": id }, (result) =>{
                if (result.code == web_status.SUCCESS) {
            	    $.modal.msgSuccess(result.msg);
            	    window.location.reload()
                }else {
                    $.modal.alertError(result.msg);
                }
            });
        })
    }
</script>
{% endblock %}
